#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
using ll = long long;
void solve()
{
    ll n;
    cin >> n;
    vector<vector<int>> a(n+1, vector<int>(n+1, 0));

    vector<int> ans(2*n+1, 0);
    set<int> s;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            cin >> a[i][j];
            if(ans[i+j]==0)
            {
                ans[i+j]=a[i][j];
                s.insert(a[i][j]);
            }
        }
    }
    int missing = 1;
    while (s.count(missing)) {
        missing++;
    }
    ans[1] = missing;

    for (ll i = 1; i <= 2 * n;i++)
    {
        cout << ans[i] << " ";
    }
    cout << "\n";
}
int main()
{
    int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
   return 0;
}
